//数据库日志模块

const { EOL } = require("./common/common");

class Trace {
    constructor() {
        this.loopTime = (ini.log.loopTime > 100 || ini.log.loopTime < 10 ) ? 10 : ini.log.loopTime;
        this.logText = [];              //要写入日志的内容     
        setInterval(async() => {
            this.writeLog();
        }, this.loopTime * 1000);
    }

    writeLog() {
        let text = '';
        for(let i=0;i<this.logText.length;i++) {
            text += this.logText[i] + EOL;
        }
        if(!text || text * 1 ===0) {
            return;
        }
        log.log(text);
        this.logText = [];      //写入之后清理
    }

    setLog(text) {
        this.logText.push(text);
    }
}

module.exports = Trace;